class DependencyUtil:
    def __init__(self):
        self.dependency_cache = {}
    
    def save_dependency(self, key, value):
        """保存依赖数据"""
        self.dependency_cache[key] = value
    
    def get_dependency(self, key):
        """获取依赖数据"""
        return self.dependency_cache.get(key)
    
    def replace_dependencies(self, data):
        """替换数据中的依赖变量"""
        if isinstance(data, str):
            # 替换格式如 ${dependency_key} 的变量
            for key, value in self.dependency_cache.items():
                placeholder = f"${{{key}}}"
                if placeholder in data:
                    data = data.replace(placeholder, str(value))
            return data
        elif isinstance(data, dict):
            return {k: self.replace_dependencies(v) for k, v in data.items()}
        elif isinstance(data, list):
            return [self.replace_dependencies(item) for item in data]
        return data